
<?php
/**
 * 
	面向对象
	http://192.168.33.10/CI/index.php/demo/obj_control/test
 * 
 * 
 */

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Obj_Control extends CI_Controller {
	

	var $header_data;
	var $body_data;
	
	/**
	 * 后面可以config相关参数赋值给构造器中类变量
	 * @param unknown $debug
	 * @param unknown $showdebug
	 * @param unknown $openId
	 */
	function __construct(){
		parent::__construct();	// 必须显示的调用，否则将覆盖父类的方法
		$this->config->load('_myconfig.php');	// ！后面用配置文件的取代硬编码
		$this->header_data['title']=$this->config->item('mytitle');;
		$this->header_data['showdebug']=true;
		$this->header_data['debug']=true;
		$this->load->helper('url');
		
	}
	
	
	/**
	 * 不想被URL访问私有方法
	 */
	private function show_header(){
		$this->load->view('jjr/block/header',$this->header_data);
	}
	
	private function show_footer(){
		$this->load->view('jjr/block/footer');
	}
	
	private function show_body($content){
		$body_data['content']=$content;
		$this->load->view('jjr/block/body',$body_data);
	}
	
	// 测试自定义对象  注意由于是调用$this->load->library 是调用不了构造方法，所以zh ji
	public function  test_obj(){
		$this->load->library('jjr/Myclass');
		
		echo 	$this->myclass->get_name('bob'); 
		
	}
	
	
	
	public function test(){
		$this->show_header();
		$output = '<div id="test" class="_hide">';
		$output .= '这如果在showdebug=false模式下会隐藏';
		$output .= '</div>';
		$this->show_body($output);
		$this->show_footer();
	}

	// 菜单项
	/**
	 * eg:http://192.168.33.10/CI/index.php/menu_control/item
	 * 
	 * eg:http://192.168.33.10/CI/index.php/test_control/test
	 */
	public function index(){
		
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		$showdebug = $this->config->item('showdebug');
		$header_data['debug']=$debug;
		$header_data['showdebug']=$showdebug;
		
		$openId = isset($_POST['openId'])?$_POST['openId']:'';
		$state = isset($_POST['state'])?$_POST['state']:'';
		$creator = isset($_POST['creator'])?$_POST['creator']:0;
		$item = isset($_POST['item'])?$_POST['item']:'';
		
		$header_data['openId']=$openId;
		$header_data['state']=$state;
		$header_data['item']=$item;
		$header_data['creator']=$creator;
		
		
		$item='test_model';	// 测试
		
		if($item＝='test_model'){
			$openId="aaa";
			
			
			$this->load->helper('url');
			
			
			
		}
		
		if($item==1){	//home
			$this->load->model('user_model');
			$user = $this->user_model->getUserByOpenId($openId);	//由openId查询user
			
			$data['openId']=$openId;	// 便于entrance.php缓存使用，方便在导航跳转时候识别客户
			$data['state']=$state;
			$data['creator']=isset($user['id'])?$user['id']:0;
			$data['name']=isset($user['name'])?$user['name']:'SomeBody';
			$data['flag']=isset($flag)?$flag:-1;	
			
			
			
			$header_data['title']='回到首页';
			$this->load->view('jjr/block/header',$header_data);
			$this->load->view('jjr/index',$data);
			$this->load->view('jjr/block/footer');
		}
		
		if($item==2){	//add client
			$header_data['title']='推荐客户';
			$this->load->view('jjr/block/header',$header_data);
			$this->load->view('jjr/client1');
			$this->load->view('jjr/block/footer');
		}
		if($item==31){	//add client
			$header_data['title']='个人中心|我的信息';
			$this->load->view('jjr/block/header',$header_data);
			$this->load->view('jjr/block/footer');
		}
		if($item==32){	//add client
			$page=1;
			$_page_size=10;
			$this->load->model('client_model');
			$data = $this->client_model->query_page($creator,($page-1)*$_page_size,$_page_size);
			
			
			$header_data['title']='个人中心|我的客户';
			$this->load->view('jjr/block/header',$header_data);
			$this->load->view('jjr/client_show',$data);
			$this->load->view('jjr/block/footer');
		}
		if($item==4){	//add client
			$header_data['title']='扩展功能';
			$this->load->view('jjr/block/header',$header_data);
			$this->load->view('jjr/block/footer');
		}
		
		if($item==999){	//add client
			$header_data['title']='经纪人';
			$this->load->view('jjr/block/header',$header_data);
			
			if($state==0)
				$data['msg']="请等待审核通过";
			if($state==-1)
				$data['msg']="请点左下方“回到首页”然后注册";
			$this->load->view('jjr/msg',$data);
			$this->load->view('jjr/block/footer');
		}
		
		
		
		
	}
	

	
}
	
	
	

	

	
	
	
	
	


/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */